#!/usr/bin/perl -w
use strict;

my $input_file = $ARGV[0];

my $ex_time   = 0;
my $c_to_c    = 0;
my $comp_time = 0;
my $comm_time = 0;

my $count = 0;

printf ("Using $input_file\n");

open (INFILE, "<$input_file") or die "$!";

while (my $line = <INFILE>) {
  if ($line =~ m/Computation Time/) {
    $line =~ s/^(.*)\:\s+//;
    $line =~ s/\s(.*)\s//;
    $ex_time += $line;
    
  } elsif ($line =~ m/Total Comp Time/) {
    $line =~ s/^(.*)\:\s+//;
    $line =~ s/\s(.*)\s//;
    $comp_time += $line;

  
  } elsif ($line =~ m/Communication Time/) {
    $line =~ s/^(.*)\:\s+//;
    $line =~ s/\s(.*)\s//;
    $comm_time += $line;
    $ex_time += $line;
  
  } elsif ($line =~ m/C-to-C Ratio/) {
    $line =~ s/^(.*)\:\s+//;
    $line =~ s/\s(.*)\s//;
    $c_to_c += $line;
  
  } elsif ($line =~ m/Number of processors/) {
    $count++;
  }
}

$ex_time /= $count;
$comp_time /= $count;
$comm_time /= $count;
$c_to_c /= $count;

printf ("Execution time     = $ex_time\n");
printf ("Computation time   = $comp_time\n");
printf ("Communication time = $comm_time\n");
printf ("C-to-C Ratio       = $c_to_c\n");

printf ("count...$count\n");
